package com.rzwl.single.server.ctrl;

import com.rzwl.single.server.dao.ScoreDao;
import com.rzwl.single.server.entity.Score;
import com.rzwl.single.server.entity.ScoreVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Optional;

/**
 * @author : championjing
 * @ClassName: ScoreCtrl
 * @Description: 
 * @Date: 2020-08-02 19:49
 */
@RequestMapping("/score")
@RestController
public class ScoreCtrl {
    
    @Autowired
    ScoreDao scoreDao;
    
    @PostMapping
    public ScoreVO save(@RequestBody ScoreVO scoreVO){
        
        Score save = scoreDao.save(scoreVO.transfer());

        return save.transfer();
    } 
    
    @GetMapping("/{id}")
    public ScoreVO findOne(@PathVariable Long id){

        Optional<Score> byId = scoreDao.findById(id);
        if (byId.get() != null) {
            return byId.get().transfer();       
        } else {
            return null;
        }
    }
}
